package archer.framework.protocol.exception;

import archer.framework.core.exception.BaseException;
import archer.framework.protocol.result.ExecuteResult;
import archer.framework.protocol.result.ResultCode;

/**
 * @author kent
 * @date 16/7/1.
 */
public abstract class BusinessException extends BaseException {

    /**
     * code
     */
    private String resultCode;

    /**
     * code ext
     */
    private String resultCodeExt;

    /**
     * message
     */
    private String resultMsg;

    /**
     * data
     */
    private Object resultData;


    public BusinessException(String resultCode, String resultMsg) {

        this(resultCode, resultMsg, null);
    }

    public BusinessException(String resultCode, String resultMsg, Object resultData) {

        this(resultCode, resultMsg, null, resultData);
    }

    public BusinessException(String resultCode, String resultMsg, String resultCodeExt, Object resultData) {

        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        this.resultCodeExt = resultCodeExt;
        this.resultData = resultData;
    }

    public BusinessException(ResultCode resultCode) {

        this(resultCode.name(), resultCode.getMsg());
    }

    public BusinessException(ResultCode resultCode, String resultMsg) {

        this(resultCode.name(), resultMsg);
    }

    /**
     * 转成ExcuteResult
     *
     * @return
     */
    public ExecuteResult toExecuteResult() {
        return new ExecuteResult(
                getResultCode(),
                getResultMsg(),
                getResultCodeExt(),
                getResultData()
        );
    }


    //-------------------------------- getter setter -----------------------------------

    public String getResultCode() {
        return resultCode;
    }

    public BusinessException setResultCode(String resultCode) {
        this.resultCode = resultCode;
        return this;
    }

    public String getResultCodeExt() {
        return resultCodeExt;
    }

    public BusinessException setResultCodeExt(String resultCodeExt) {
        this.resultCodeExt = resultCodeExt;
        return this;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public BusinessException setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
        return this;
    }

    public Object getResultData() {
        return resultData;
    }

    public BusinessException setResultData(Object resultData) {
        this.resultData = resultData;
        return this;
    }
}
